/*
https://leetcode-cn.com/problems/global-and-local-inversions/solution/quan-ju-dao-zhi-yu-ju-bu-dao-zhi-by-leetcode/
 */
public class Solution775 {
    public boolean isIdealPermutation(int[] nums) {
        for (int i=0;i<nums.length;i++){
            if (Math.abs(i-nums[i])>1){
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(new Solution775().isIdealPermutation(new int[]{1,0,2}));
    }
}
